<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
if ( ! function_exists('is_login'))
{
    function is_login($var = '')
    {
        $specialCharactor = "!@#$%^&*()abcxyz0987654312";
        if(!isset($_SESSION['username']) 
                || !isset($_SESSION['username']) 
                || !isset($_COOKIE["togetherOAuth"])){
            return False;
        }
        $user = $_SESSION['username'];
        $pass = $_SESSION['password'];
        $togetherOAuthCookie = $_COOKIE["togetherOAuth"];
        $togetherOAuth = md5($user + $pass + $specialCharactor);
        if(strcmp($togetherOAuthCookie, $togetherOAuth) == 0){
            return True;  
        }
        return False;
        
      
    }   
}

/**
 * Lấy thông tin của user hiện tại đang đăng nhập
 * @return array
 * 
 */

if ( ! function_exists('current_user_info'))
{
    function current_user_info()
    {
        if (!isset($_SESSION["username"])){
            return null;
        }
        $username = $_SESSION["username"];
        // Get a reference to the controller object
        $CI = get_instance();
        // You may need to load the model if it hasn't been pre-loaded
        $CI->load->model('muser');

        // Call a function of the model
        $uin = $CI->muser->get_user_info($username);
        return $uin;
    }   
}



?>
